<template>
  <div id="box">
    <div id="login">
      <div id="l-box">
        <h2>注册</h2>
        <p style="margin: 0">
          <i class="el-icon-user-solid"></i>
          <el-input v-model="relationName" placeholder="公司名称"></el-input>
        </p>
        <p style="margin: 0">
          <i class="el-icon-user-solid"></i>
          <el-input
            v-model="loginUser.loginName"
            placeholder="管理员账号"
          ></el-input>
        </p>
        <p>
          <i class="el-icon-lock"></i>
          <el-input
            v-model="loginUser.password"
            type="password"
            placeholder="管理员密码"
            show-password
          ></el-input>
        </p>
        <p>
          <i class="el-icon-lock"></i>
          <el-input
            v-model="rePassword"
            type="password"
            placeholder="确认密码"
            show-password
          ></el-input>
        </p>
        <p>
          <el-row>
            <el-button
              id="login-btn"
              v-loading="showFlag"
              type="primary"
              @click="doLogin"
              style="margin-bottom: 20px"
              >确认注册</el-button
            >
          </el-row>
        </p>
        <router-link
          style="color: #c77869; position: relative; left: 150px; top: -50px"
          to="login"
          >去登录</router-link
        >
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      relationName: "",
      loginUser: {
        loginName: "",
        password: "",
        userRole: "",
      },
      rePassword: "",
      showClose: false,
      showFlag: false,
    };
  },
  methods: {
    doLogin() {
      if (
        this.loginUser.password === "" ||
        this.loginUser.loginName === "" ||
        this.loginUser.relationName === ""
      ) {
        alert("请继续填写信息！");
        return;
      }
      if (this.loginUser.password.length < 6) {
        alert("密码长度不可小于6位！");
        return;
      }
      if (this.loginUser.password !== this.rePassword) {
        alert("请输入相同的密码！");
        return;
      }
      this.axios
        .post("/info/employee/register", {
          password: this.loginUser.password,
          employeeCode: this.loginUser.loginName,
          relationName: this.relationName,
        })
        .then((rs) => {
          if (rs.data.code == 200) {
            alert("注册成功！");
            this.goto("login");
          } else {
            alert(rs.data.msg);
          }
        });
    },
    goto(path) {
      this.$router.push(path);
    },
  },
};
</script>

<style scoped>
#box {
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  background-image: url(../../assets/image/bg.jpg);
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
}

#l-box {
  width: 100%;
  /* height: 280px; */
  background-color: white;
}

.el-input {
  margin-left: 10px;
}

#login {
  width: 440px;
  margin: auto;
  position: relative;
  top: 70px;
  text-align: center;
  border-radius: 30px;
  overflow: hidden;
}

.el-input {
  width: 240px;
  margin-bottom: 10px;
}

#login input {
  width: 240px;
  height: 34px;
  font-size: 16px;
  padding-left: 10px;
  border: 1px solid #a5a6a7;
  /* border: none;
  border-bottom: 1px solid gray; */
  margin-left: 10px;
  outline: none;
}

/* .el-input--suffix .el-input__inner {
  position: relative;
  left: 50px;
} */

#l-box h2 {
  margin: 0;
  padding: 0;
  position: relative;
  top: -30px;
  color: #c77869;
}

#l-box {
  padding-top: 60px;
}

#login-btn {
  background-color: #c77869;
  border: none;
  width: 180px;
  margin-top: 30px;
  height: 40px;
}
</style>